import QtQuick 2.6
import QtQuick.Layouts 1.2

import "../../Base/UiBase"
import "../../Base/Config"
import Code 1.0

import Cpp.Type 1.0

RowLayout {
    id: headBlock

    property alias headSource: headImage.source
    property alias username: usernameLabel.text
    property int subject
    property string time
    property alias location: locationLabel.text

    onSubjectChanged: {
        if (subject === Subject.Pe)
            subjectImage.source = "../../../resources/tcommunity/posts/tiyu.svg"
        else if (subject === Subject.Paint)
            subjectImage.source = "../../../resources/tcommunity/posts/meishu.svg"
        else
            subjectImage.source = "../../../resources/tcommunity/posts/yinyue.svg"
    }

    height: 90 * Size.ratio

    anchors {
        left: parent.left
        right: parent.right
    }
    Item {
        id: headImageBlock
        width: 90 * Size.ratio
        height: 90 * Size.ratio
        SvgzImage {
            id: headImage

            width: 72 * Size.ratio
            height: 72 * Size.ratio
            anchors.centerIn: parent
        }
    }

    ColumnLayout {
        spacing: 0
        height: headImage.height
        anchors {
            left: headImageBlock.right
            right: headBlock.right
            verticalCenter: headBlock.verticalCenter
        }

        Text {
            id: usernameLabel
            font.pixelSize: Size.normalFont
        }
        SvgzImage {
            id: subjectImage
            width: 35 * Size.ratio
            height: 25 * Size.ratio
        }

        Text {
            id: locationLabel
            anchors.bottom: parent.bottom

            font.pixelSize: Size.smallFont

            Text {
                id: timeLabel
                text: Helper.dateToReadable(time)
                anchors.verticalCenter: locationLabel.verticalCenter
                x: root.width - contentWidth - headImageBlock.width - 10 * Size.ratio
                font.pixelSize: Size.smallFont
            }
        }
    }
}
